﻿using ASoft.Web.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Asoft.Web.Controllers.Wap
{
    public class WapRoomController : Controller
    {
        //
        // GET: /WapRoom/

        public ActionResult Index()
        {
            var repository = (new WebRoomDataRepository());
            var condition = new Dictionary<string, string>();
            condition["customcode"] = CurrentContext.CustomCode;
            var result = repository.GetEntities(condition, 0, 300, new string[] { "id" }, new string[] { "asc" });
            ViewData["rooms"] = result;
            ViewData["wsd"] = repository.GetWSData(CurrentContext.CustomCode);
            return View();
        }

        [HttpPost]
        public ActionResult ChangeCurrentCustomCode()
        {
            string customCode = Request["customCode"];
            if (CurrentContext.Customs.Count(p => p.Code == customCode) > 0)
            {
                CurrentContext.CustomCode = customCode;
            }
            CurrentContext.Customs.Clear();
            return View("RoomRedirect");
        }

        public ActionResult Detail(int id)
        {
            var condition = new Dictionary<string, string>();
            condition["customcode"] = CurrentContext.CustomCode;
            var result = (new WebRoomDataRepository()).GetEntities(condition).FirstOrDefault(p => p.Id == id);
            ViewData["room"] = result;
            return View();
        }
    }
}
